﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>第三方设置</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>

    <script>
        $(function () {
            initTable();
        });

        //初始化表格  
        function initTable() {
            $('#load').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/ThirdPartyPayment/getgrid',
                sortName: 'PayID',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'PayID',
                pageSize: 20,
                singleSelect: true,
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'PayID', title: '第三方支付ID', width: 100, sortable: true, align: 'center', hidden: true },
					{ field: 'PayName', title: '第三方支付名称', width: 100, sortable: true, align: 'center' },
					{
					    field: 'PayOpen', title: '状态', width: 250, sortable: true, align: 'center',
					    formatter: function (cellvalue, options, rowObject) {
					        if (cellvalue == '1') return "仅开放充值";
					        if (cellvalue == '2') return "仅开放直接支付";
					        if (cellvalue == '3') return "开放充值和支付";
					        if (cellvalue == '0') return "不开放";
					    }
					},
                    { field: 'PayBZ', title: "备注", width: 100, align: 'center' }
                ]],
                toolbar: '#tb'
            });
        }

        //绑定搜索条件
        function BindStatType() {
            $('#PayOpen').combobox({
                valueField: 'id',
                textField: 'text',
                data: [{
                    "id": "1",
                    "text": "仅开放充值"
                }, {
                    "id": "2",
                    "text": "仅开放直接支付"
                }, {
                    "id": "3",
                    "text": "开放充值和支付"
                }, {
                    "id": "0",
                    "text": "不开放"
                }, {
                    "id": "-1",
                    "text": ""
                }]
            });
        }

        //添加上架信息对话框
        function AddDialog() {
            $('#DetailDialog').dialog('open').dialog('setTitle', '新增第三方支付');
            $("#Tag").textbox('setValue', 1);
            BindStatType();
            ClearText();
            document.getElementById("ok").style.display = "block";
        }

        //修改上架信息对话框
        function UpdateDialog() {
            var UpdateInfoID = $("#load").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#DetailDialog").dialog("open").dialog("setTitle", "修改第三方支付信息");
                $("#Tag").textbox('setValue', 2);
                document.getElementById("ok").style.display = "block";
                BindStatType();
                BingDetail();
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //查看详细窗口
        function OpenDetail() {
            var UpdateID = $("#load").datagrid("getSelections");
            if (UpdateID.length == 1) {
                $("#DetailDialog").dialog("open").dialog("setTitle", "第三方支付详细信息");
                document.getElementById("ok").style.display = "none";
                BindStatType();
                BingDetail();
            }
            else {
                $.messager.alert("友情提示", "每次只能查看一行数据，你已经选择了<font color='red' size='6'>" + UpdateID.length + "</font>行");
            }
        }

        //删除上架信息对话框
        function DeleteDialog() {
            //首先获取选中的上架信息的所有信息
            var checkdata = $("#load").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#load").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    PayID: checkdata.PayID,
                    PayOpen: checkdata.PayOpen,
                    PayName: checkdata.PayName,
                    PayBZ: checkdata.PayBZ,//备注
                };
                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + "</font>该条第三方支付吗？", function (Del) {
                    if (Del) {
                        $.post("/ThirdPartyPayment/SetOrderPay?Tag=" + 3, postdata, function (data) {
                            if (data == "1") {
                                $.messager.alert("友情提示", "删除成功");
                                initTable();
                            }
                            else if (data == "-1") //czx: Session超时异常，直接跳转到登录页面
                            {
                                $.messager.alert("提示", "登录超时异常", "warning", function () {
                                    window.location.href = "../../login/loginpage";

                                });

                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
            }
        }

        //保存
        function submitForm() {
            var payid = $("#PayID").textbox('getValue');//第三方支付ID
            var payopen = $("#PayOpen").combobox('getValue');//状态
            var payname = $("#PayName").textbox('getValue');//支付名称
            var paybz = $("#PayBZ").textbox('getValue');//支付名称
            var Tag = $("#Tag").textbox('getValue');//支付名称
            var postdata = {
                PayID: payid,
                PayOpen: payopen,
                PayName: payname,
                PayBZ: paybz,//备注
            };
            //首先判断前台的验证是否通过
            if (postdata.PayOpen != "-1" & postdata.PayID != "" & postdata.PayName != "") {
                //使用异步实现修改用户信息
                $.post("/ThirdPartyPayment/SetOrderPay?Tag=" + Tag, postdata, function (date) {
                    if (date == "1") {
                        $("#DetailDialog").dialog('close');
                        $("#load").datagrid('reload');
                        $.messager.alert("友情提示", "更新成功");
                    }
                    else if (date == "-1") //czx: Session超时异常，直接跳转到登录页面
                    {
                        $.messager.alert("提示", "登录超时异常", "warning", function () {
                            window.location.href = "../../login/loginpage";

                        });

                    }
                    else {
                        $.messager.alert("友情提示", "删除失败:" + date);
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "请填写第三方支付ID、名称、状态");
            }
        }

        //获取用户信息绑定
        function BingDetail() {
            var datas = $("#load").datagrid("getSelections")[0]; //获取选中行数据
            $("#PayID").textbox('setValue', datas.PayID);
            $("#PayName").textbox('setValue', datas.PayName);
            $("#PayBZ").textbox('setValue', datas.PayBZ);
            $("#PayOpen").combobox('setValue', datas.PayOpen);
            document.getElementById("PayID").readOnly = "true";
            document.getElementById("PayName").readOnly = "true";
            document.getElementById("PayOpen").readOnly = "true";
            document.getElementById("PayBZ").readOnly = "true";
        }

        //清空信息
        function ClearText() {
            $("#PayID").textbox('setValue', "");
            $("#PayName").textbox('setValue', "");
            $("#PayOpen").combobox('setValue', "-1");
            $("#PayBZ").textbox('setValue', "");
        }

    </script>

</head>
<body style="padding: 0;">
    <!--表格加载S-->
    <div>
        <table id="load" style="width: auto;"></table>
    </div>
    <!--表格加载E-->

    <!--工具栏S-->
    <div id="tb" style="padding: 5px; height: auto; width: 100%;">
        <div style="margin-bottom: 5px">
            <a href="#" class="easyui-linkbutton" id="btndetail" iconcls="icon-more" onclick="OpenDetail()" plain="true">明细</a>
            <a href="#" class="easyui-linkbutton" id="btnadd" iconcls="icon-add" onclick="AddDialog()" plain="true">新增</a>
            <a href="#" class="easyui-linkbutton" id="btnedit" iconcls="icon-edit" onclick="UpdateDialog()" plain="true">编辑</a>
            <a href="#" class="easyui-linkbutton" id="btndell" iconcls="icon-cancel" onclick="DeleteDialog()" plain="true">删除</a>
            <hr style="margin-top: 5px" />
        </div>
    </div>
    <!--工具栏E-->

    <!--修改S-->
    <div id="DetailDialog" class="easyui-dialog" style="width: 550px; padding: 10px 0" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <table width="500px">
            <tr hidden="hidden">
                    <td>
                        <input class="easyui-textbox" type="text" id="Tag" name="Tag" />
                    </td>
                </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">第三方支付ID：</td>
                <td style="padding: 10px">
                    <input class="easyui-textbox" id="PayID"  style="width: 200px; height: 24px" data-options="required:true"/>
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">第三方名称：</td>
                <td style="padding: 10px">
                    <input id="PayName" class="easyui-textbox" style="width: 200px; height: 24px" data-options="required:true">
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">状态：</td>
                <td style="padding: 10px">
                    <input id="PayOpen" class="easyui-combobox" style="width: 200px; height: 24px" data-options="required:true">
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">备注：</td>
                <td style="padding: 10px">
                    <input id="PayBZ" class="easyui-textbox" style="width: 200px; height: 24px;">
                </td>
            </tr>
        </table>
        <br />
        <br />
        <div id="ok" align="center" style="display: block">
            <a href="javascript:void(0)" id="submit" class="easyui-linkbutton" iconcls="icon-ok" onclick="submitForm()">保存</a> &nbsp;&nbsp;&nbsp;&nbsp;
            <a id="btnUpdateCancel" href="javascript:(0)" onclick="javascript:$('#DetailDialog').dialog('close')" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>
        </div>
    </div>
    <!--修改E-->

</body>
</html>

